﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetPartyMemberCost : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyMemberCostOutParam result = new PartyMemberCostOutParam();
            PartyMemberCostInParam param = new PartyMemberCostInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyMemberCostInParam;
                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.year))
                {
                    result.code = "0";
                    result.desc = "用户ID,查询年份不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (CommonUtils.IsDisableUsers(param.user_id))
                    {
                        result.code = "0";
                        result.desc = "用户状态有问题，请联系管理员";

                        isFlag = false;
                    }
                }

                if (param.status != "0" && param.status != "1" && param.status != "2")
                {
                    result.code = "0";
                    result.desc = "状态必须为 0(全部)，1(已缴纳)，2(未缴纳)";

                    isFlag = false;
                }

                if (isFlag)
                {
                    try
                    {
                        int year = Convert.ToInt32(param.year);
                        if (year <= 1900 || year > 9999)
                        {
                            result.code = "0";
                            result.desc = "请输入正确的查询年份值";

                            isFlag = false;
                        }
                    }
                    catch
                    {
                        result.code = "0";
                        result.desc = "请输入正确的查询年份值";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (param.status == "2")
                    {
                        result.code = "0";
                        result.desc = "目前不支持未缴纳状态党费的查询";

                        isFlag = false;
                    }
                } 

                if(isFlag)
                {
                    PartyMemberCost itemTemp;
                    DataSet ds = InterfaceHelper.GetPartyMemberCost(param.user_id, param.year);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    { 
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new PartyMemberCost();
                            itemTemp.money = dr["money"].ToString();
                            itemTemp.month = dr["month"].ToString();
                            itemTemp.status = dr["status"].ToString(); 

                            result.data.list.Add(itemTemp);
                        }
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetPartyMemberCost", SerializeHelper.JsonSerializer<PartyMemberCostInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyMemberCostInParam, PartyMemberCostOutParam>();
            else
                SafeProcessRequest<PartyMemberCostInParam, PartyMemberCostOutParam>();
        }
    }

    #region 请求参数
    public class PartyMemberCostInParam
    {
        /// <summary>
        /// 必填 用户ID
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 必填 查询年份
        /// </summary>
        public string year
        { get; set; }

        /// <summary>
        /// 状态 0:全部，1：已缴纳，2：未缴纳
        /// </summary>
        public string status
        { get; set; } 
    }
    #endregion

    #region 结果参数
    public class PartyMemberCostOutParam
    {
        public PartyMemberCostOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new PartyMemberCostList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 用户党费缴纳信息
        /// </summary> 
        public PartyMemberCostList data
        { get; set; }
    }

    public class PartyMemberCostList
    {
        public PartyMemberCostList()
        {
            //total_pages = 0;
            list = new List<PartyMemberCost>();
        }

        public List<PartyMemberCost> list { get; set; }

        ///// <summary>
        ///// 总页数
        ///// </summary>
        //public int total_pages
        //{ get; set; }
    }

    /// <summary>
    /// 用户党费缴纳信息
    /// </summary>
    public class PartyMemberCost
    {
        /// <summary>
        ///	月份 
        /// </summary>
        public string month
        { get; set; }

        /// <summary>
        ///	金额 
        /// </summary>
        public string money
        { get; set; }

        /// <summary>
        ///	状态 1：已缴纳，2：未缴纳 
        /// </summary>
        public string status
        { get; set; } 
    }
    #endregion 
}